package rsj.service.export.product.test;

import com.rlyy.aibase.utils.base.TableNode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import rsj.api.org.entity.UsageReportParam;
import rsj.service.export.product.IProductDownloadDetail;
import rsj.service.usage.IUsageTemplateMethod;
import rsj.sql.product.ProductProduceDetailDao;

/**
 * 产品管理-测试环境导出全部详情
 *
 * @author yuanqinglong
 * @since 2021/3/5 14:00
 */
@Component
public class ProductTestExportAllDetail implements IProductDownloadDetail {


    @Autowired
    private ProductProduceDetailDao productProduceDetailDao;


    @Override
    public TableNode queryTableByPage(UsageReportParam usageReportParam) {
        return productProduceDetailDao.testExportAllDetail(usageReportParam);
    }

    /**
     * 测试环境导出全部详情
     *
     * @param usageReportParam 参数
     * @return sql
     */
    @Override
    public String generateQueryStatement(UsageReportParam usageReportParam) {
        return " SELECT stat_prod_name,stat_prod_uid,stat_org_sname,stat_orgp_id,detail.log_ip," +
                " detail.log_reqtime,detail.log_reqsernumber,detail.log_iscost,detail.log_dsname," +
                " detail.log_dsreqtime,detail.log_dsnumber,detail.log_dscost " +
                " FROM sys.sys_stat stat LEFT JOIN sys.oper_log detail ON detail.log_orgp_id = stat.stat_orgp_id AND stat_prod_uid = log_prod_uid" +
                " WHERE stat_prod_uid = #{statProdUid} AND stat_env ='" + IUsageTemplateMethod.TEST_ENVIRONMENT + "'";
    }


    /**
     * 生成导出的文件名称
     *
     * @param usageReportParam usageReportParam参数
     * @return 文件名
     */
    @Override
    public String generateExportFileName(UsageReportParam usageReportParam) {
        return this.queryProdNameByStatProdUid(usageReportParam.getStatProdUid()) + "-测试环境-全部使用详情.xlsx";
    }

}
